home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10964 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: erich.triumf.ca!bennett
  2. From: bennett@erich.triumf.ca (P.Bennett)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginer C please help me
  5. Date: 20 Mar 1996 21:38 PST
  6. Organization: TRIUMF: Tri-University Meson Facility
  7. Distribution: world
  8. Message-ID: <20MAR199621383426@erich.triumf.ca>
  9. References: <DoLCFx.B7x.0.bloor@torfree.net>
  10. NNTP-Posting-Host: erich.triumf.ca
  11. News-Software: VAX/VMS VNEWS 1.50    
  12.  
  13. In article <DoLCFx.B7x.0.bloor@torfree.net>, bz786@torfree.net (Sherif Asif) writes...
  14. >This may be a stupid mistake but "please help" me.
  15.  
  16. >#include <stdio.h>
  17. >#include <math.h>
  18. >main ()
  19. >{
  20. >float n;
  21. >n=(9/5);
  22. >printf ("n=   %1.3f\n", n);
  23. >}
  24. >I have complied and run the programme & I got the answer n=1.000
  25. >but Iam supposed to get answer 1.8.
  26. >Why I got this answer?
  27.  
  28. 9 and 5 are integers, so the division will be done as an int operation - the
  29. result will also be an int.
  30.  
  31. You can make this work as you want by making at least one of the operands a
  32. float like: 9.0/5.0 - this will do a float division, with a float result.
  33.  
  34.  
  35.  
  36. Peter Bennett VE7CEI                | Vessels shall be deemed to be in sight
  37. Internet: bennett@triumf.ca         | of one another only when one can be
  38. Packet: ve7cei@ve7kit.#vanc.bc.ca   | observed visually from the other
  39. TRIUMF, Vancouver, B.C., Canada     |                          ColRegs 3(k)
  40. GPS and NMEA info and programs: ftp://sundae.triumf.ca/pub/peter/index.html
  41. or: ftp://ftp-i2.informatik.rwth-aachen.de/pub/arnd/GPS/peter/index.html
  42.  
  43.  
  44.  
  45.  
  46.  
  47.